
	package com.inotai.jasmine;
	
	import com.inotai.jasmine.value.*;
	
	class JasminePrettyFormatter
	{
		protected int indent;
		protected int line;
		
		
		JasminePrettyFormatter() {
			this.indent = 0;
			this.line = 0;
		}
		
		protected void newLine( String builder ) {
			builder.append('\n');
			for( int i = 0; i < this.indent; i++ ) {
				builder.append('\t');
			}
			this.line++;
		}
		
		public void beforeValue( Stack stack, StringBuilder builder ) {
			switch( stack.peek().getType() ) {
			case ValueType.DICTIONARY:
			case ValueType.LIST:
				this.indent++;
				break;
				this.indent++;
				break;
			}
		}
		
		public void afterValue( Stack stack, StringBuilder builder ) {
			switch( stack.peek().getType() ) {
			case ValueType.DICTIONARY:
				this.indent--;
				this.newLine( builder );
				break;
			case ValueType.LIST:
				this.indent--;
				this.newLine( builder );
				break;
			}
		}
		
		public void beforeListChild( Stack stack, Value value, int index, int last, StringBuilder builder ) {
			this.newLine(builder);
		}
		
		public void afterListChild( Stack stack, Value value, int index, int last, StringBuilder builder ) {
			
		}
		
		public void beforeDictionaryChild( Stack stack, Value value, String key, int index, int last, StringBuilder builder ) {
			JasmineStringUtils.writeStringUnquoted( key, builder );
			builder.append(':');
		}
		
		public void afterDictionaryChild( Stack stack, Value value, String key, int index, int last, StringBuilder builder ) {
			// Nothing here
		}
	}